package com.meitutest.autoscript.T9;

import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiSelector;

import com.meitutest.autoscript.utils.TestReport;


class FluencyHelper {
    private T9 t9;
    private UiDevice uiDevice;
    private static int defaultSlideCount = 20;
    private static int smallCount = 5;


    FluencyHelper(T9 t9) {
        this.t9 = t9;
        this.uiDevice = t9.uiDevice;
    }

    /**
     * 联系人，滑动50次
     */
    void contactTest01() {
        try {
            t9.clickAppIcon("联系人");
            Thread.sleep(1000);
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromBottom(50);
                Thread.sleep(1000);
            }
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromTop(50);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.e("FluencyHelper_contactTest01: " + e.getMessage());
        }
    }

    /**
     * 日历，滑动50次
     */
    void calenderTest01() {
        try {
            t9.clickAppIcon("日历");
            Thread.sleep(1000);
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromRight(10);
                Thread.sleep(1000);
            }
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromLeft(10);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.e("FluencyHelper_calenderTest01: " + e.getMessage());
        }
    }

    /**
     * 通话记录，滑动50次
     */
    void dailerTest01() {
        try {
            t9.clickAppIcon("拨号");
            uiDevice.findObject(new UiSelector().resourceId("com.android.dialer:id/mts_icon").instance(1)).click();
            Thread.sleep(1000);
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromBottom(50);
                Thread.sleep(1000);
                TestReport.i("FluencyHelper_dailerTest01: ");
            }
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromTop(50);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.e("FluencyHelper_dailerTest01: " + e.getMessage());
        }
    }

    /**
     * 信息，滑动50次
     */
    void mmsTest01() {
        try {
            t9.clickAppIcon("信息");
            Thread.sleep(1000);
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromBottom(50);
                Thread.sleep(1000);
            }
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromTop(50);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.e("FluencyHelper_mmsTest01: " + e.getMessage());
        }
    }


    /**
     * 便签，滑动50次
     */
    void noteTest01() {
        try {
            t9.clickAppIcon("美图便签");
            Thread.sleep(1000);
            for (int i = 0; i < smallCount; i++) {
                t9.swipeFromBottom(50);
                Thread.sleep(1000);
            }
            for (int i = 0; i < smallCount; i++) {
                t9.swipeFromTop(50);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.e("FluencyHelper_noteTest01: " + e.getMessage());
        }
    }

    /**
     * 图库滑动50下
     */
    void photoTest01() {
        try {
            t9.clickAppIcon("图库");
            Thread.sleep(1000);
            uiDevice.findObject(By.text("相片")).click();
            Thread.sleep(1000);
            for (int i = 0; i < smallCount; i++) {
                t9.swipeFromBottom(50);
                Thread.sleep(1000);
            }
            for (int i = 0; i < smallCount; i++) {
                t9.swipeFromTop(50);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.i("FluencyHelper_photoTest01: " + e.getMessage());
        }
    }

    /**
     * 图片查看右滑50下
     */
    void photoTest02() {
        try {
            t9.clickAppIcon("图库");
            Thread.sleep(1000);
            uiDevice.findObject(By.text("相片")).click();
            Thread.sleep(1000);
            uiDevice.findObject(new UiSelector().resourceId("com.mlab.photos:id/view_thumb").instance(0)).click();
            Thread.sleep(1000);
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromRight(10);
                Thread.sleep(1000);
            }
            for (int i = 0; i < defaultSlideCount; i++) {
                t9.swipeFromLeft(10);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TestReport.e("FluencyHelper_photoTest02: " + e.getMessage());
        }
    }
}
